Repository navigation
feat!: contract helpers require the key-declared schema - #488
Merged
Merged
Conversation
Link helpers (publish, subscribe, linked_to/from and their _with forms) and observe() now require the record's key to declare the contract they carry, so a contract record declared with a schema-free Name<T> fails build() instead of silently dropping its schema from the graph and record.list. The key stays the only source of a record's schema. - core: RecordRegistrar::declared_schema / require_contract; links get a public with_contract (a requirement, never a setter); Name<T>: Debug - examples/docs: declare contract records with Key<T> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
…re_contract message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
…with_contract::<V> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Replace the build()-time contract check with a type-state on the registrar. TypedKey gains an associated Schema state (Declared for Key<T> / contract = T, Undeclared for Name<T> / payload = T), and configure hands out RecordRegistrar<'_, T, K::Schema>. - linked_to / linked_from / their _with forms and observe() require S: ContractDeclared, so they do not compile on a Name<T> record. - publish / subscribe return ContractOutboundLink / ContractInboundLink, which implement Output / Input only for ContractDeclared records. - Input / Output take the schema state as a parameter; registrar extension traits implement for any S and return &mut Self. - Remove declared_schema, require_contract and requires_contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
… state Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGkDJ9Sps6DnUDtpdbs6kD
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #487. With typed keys the key is the only source of a record's schema, so a contract record declared with a schema-free
Name<T>compiled, worked on the wire and silently dropped its schema from the dependency graph,record.listand the MCP output. The mechanical migration in #487 did this at many call sites. This PR keeps the one-source model and makes that mistake failbuild()instead.Core (
aimdb-core)RecordRegistrar::declared_schema()reads the schema the key declared.RecordRegistrar::require_contract(name, version)checks that schema and never sets it. With no declared schema, or a different one, it records a config error that points toKey<T>or#[record_key(contract = T)].InboundLink/OutboundLinkget a publicrequires_contract(name, version), replacing the test-onlywith_schema. Registering such a link callsrequire_contract; the check runs even if the link itself is rejected. It is namedrequires_contractso it does not shadow data-contracts' existingwith_contract::<V>().Name<T>gainsDebug, matchingKey<T>.schema()and the link methods, and renamed the&'static strkey test.Data contracts
publish,subscribe,linked_to,linked_from, their_withforms andobserve()now require the key to declareT..link_to()/.link_from()builders and the versioned-link builders (sends_as,with_link_codec) check nothing, so a plainName<T>record with a hand-built link stays schema-free. This keepstyped_keys_keep_schema_on_downgrade_and_plain_names_stay_schema_freevalid.Call sites
Key<T>in: the zenohros2_gateway,ros2_listenerandturtlesim_mcpexamples,remote-access-demo(Temperature, used with.observe()and as a transform input), and the docs and READMEs that use contract helpers (zenoh README, usage guide,aimdb-and-ros2,ros2-walkthrough, embassy-mqtt README,builder.rsdocs).aimdb-mqtt-connector/tests/link_ext_tests.rs, and the zenohros2_inbound,ros2_outboundandshared_sessiontests.configure::<ButtonPress>(..)turbofish is removed.aimdb-coreandaimdb-data-contractsare updated.Not changed: several READMEs still use the old keyless
configure::<T>(|reg| ..)form from before #487:aimdb-embassy-adapter,aimdb-mqtt-connectorandaimdb-knx-connector. They are out of scope here.Related Issue
Validation
aimdb-corelib tests, including the newrequires_contract_checks_the_key_schema;aimdb-mqtt-connector --test link_ext_tests;aimdb-zenoh-connector --features std,tracing,log.make testmatrix was not finished locally. The container ran out of disk partway through, and the later failures were disk-full build errors, not test results. CI is the full check.Checklist
make check): awaiting CI.Generated by Claude Code